import java.util.Stack;

public class MyStack {

    private int[] arr;
    private int size;
    private int limit;
    private Stack<Integer> data;
    private Stack<Integer> min;

    public MyStack(int limit){
        this.limit = limit;
        arr = new int[limit];
        data = new Stack<>();
        min = new Stack<>();
    }

    public void push(int val){
       if(size==limit){
           throw new RuntimeException("栈满了");
       }
       if(data.empty()){
           data.push(val);
           min.push(val);
           size++;
           return;
       }else{
           if(val<min.peek()){
               min.push(val);
           }else{
               min.push(min.peek());
           }
           data.push(val);
           size++;
       }
    }

    public int pop(){
        if(data.empty()){
            throw  new RuntimeException("栈空了");
        }
        int tmp = data.pop();
        min.pop();
        return tmp;
    }

    public int getMin(){
        if(min.empty()){
            throw  new RuntimeException("栈空");
        }
        return min.peek();
    }

    public static void main(String[] args) {
        MyStack stack = new MyStack(10);
        stack.push(10);
        stack.push(5);
        stack.push(3);
        stack.push(8);
        stack.push(12);
        stack.push(9);
        stack.pop();
        int tmp = stack.getMin();
        System.out.println(tmp);

    }

}
